// Package _range mid_range
// @Title _range
// @Description
// @Author  == 琳琳也叫王木木 ==  2021/9/1 16:47
// @Create  2021/9/1 16:47
package _range

import "go_leetcode/special_practice/3_tree"

func MidRange(root *__tree.MyTreeNode) []int {
	ans := make([]int, 0)
	if root == nil {
		return ans
	}
	stack := []*__tree.MyTreeNode{} // 根节点入栈
	cur := root
	for cur != nil || len(stack) > 0 {
		if cur != nil {
			stack = append(stack, cur)
			cur = cur.Left
		} else {
			cur = stack[len(stack)-1]    // 从栈中弹出一个元素
			stack = stack[:len(stack)-1] // 栈的长度减1
			ans = append(ans, cur.Val)
			cur = cur.Right
		}
	}
	return ans
}
